﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<NormControlDoc>>" %>

<script type="text/javascript">
    $(function () {
        $("#normControlsTable input:checkbox").change(function () {

            var checkbox = $(this);
            alert( "checkbox is " + checkbox);
            var docId = checkbox.parent().find("input:hidden")[0].val();
            alert("parent val is " + docId);
            var path = '<%: Url.RouteUrl("Default", new {controller="NormControlDocs", action="SetCompletion"}) %>' + '?id=' + docId + '&isCompleted=' + checkbox.is(':checked');

            $.ajax({
                url: path,
                success: function (data) {
                    checkbox.parents("tr")[0].replaceWith(data);
                }
            });
        });
    });
</script>

<div id="normControlDocControl">
    <% if (Model != null && Model.Count() != 0)
       { %>
    <table id="normControlsTable">
        <% foreach (var doc in Model)
           { %>
        <% Html.RenderPartial("~/Views/NormControlDocs/NormControlDocViewControl.ascx", doc); %>
        <%} %>
    </table>
    <%} %>
    <% if (ViewData["LoggedUser"] is Student)
       { %>
    <%
       using (
           Html.BeginRouteForm("Default", new { controller = "NormControlDocs", action = "Add" }, FormMethod.Post,
                               new { enctype = "multipart/form-data" }))
       {%>
    <%:Html.Hidden("StudentId", (ViewData["LoggedUser"] as User).UserId)%>
    <input type="file" id="postFile" name="postFile" />
    <input type="submit" value="Попытать счастья" />
    <%}%>
    <% } %>
</div>
